---
description: Learn how to run a local instance of the Triplit sync server for development.
---

import { Callout } from 'nextra-theme-docs';

# Local Development

Although you can connect directly to a managed or self hosted instance of a remote Triplit Database, you can also run a local instance of Triplit Database for development purposes. This not only helps separate your development and production environments, but Triplit's local development toolkit provides a lot of help for deploying updates to the Database. For this reason, we recommend running a local instance of Triplit Database when building most projects.

## Install the CLI

If you haven't already, install the Triplit CLI and initialize a project. You can find instructions for doing so [here](/getting-started).

## Start Triplit services

To start Triplit services, run the following command in your project directory:

```bash
npx triplit dev
```

By default this will start the following services:

- Triplit Console, running at `https://console.triplit.dev/local`
- Triplit Database server, running at `http://localhost:6543`

And prints a usable Service Token and Anonymous Token for connecting to the database.

## Additional environment variables

If your project has a `.env` file, you may set the following environment variables to configure the Triplit Database server:

<Callout>
  If you're using a framework like [Vite](https://vitejs.dev/guide/) or
  [Next.js](https://nextjs.org/docs) you should add additional environmental
  variables prepended with `VITE_` or `NEXT_PUBLIC_` respectively for the
  `DB_URL` and `ANONYMOUS_TOKEN`. For example, `TRIPLIT_DB_URL` would become
  `VITE_TRIPLIT_DB_URL` or `NEXT_PUBLIC_TRIPLIT_DB_URL`.
</Callout>

- `TRIPLIT_SERVICE_TOKEN` - The Service Token to use for connecting to the database for CLI commands. If not set, you may use a flag in the CLI (which takes precedent) or the CLI will prompt you for a key.
- `TRIPLIT_DB_URL` - The URL to use for connecting to the database. If not set, you may use a flag in the CLI (which takes precedent) or use the default URL for the local database.
- `TRIPLIT_JWT_SECRET` - Overrides the JWT secret used when generating local api tokens.
- `TRIPLIT_EXTERNAL_JWT_SECRET` - Overrides the JWT secret used when generating external api tokens.
- `TRIPLIT_CLAIMS_PATH` - A `.` separated path to read Triplit claims on external api tokens. If not set, claims are assumed to be at the root of the token.
- `TRIPLIT_MAX_BODY_SIZE` - The maximum body size for incoming requests. This is useful if you want to send large payloads to your server. The default value is 100, corresponding to 100MB.
